package com.yc.str;

/**
 * 字符串的操作测试
 */
public class StringTest {

    String s;

    public static void main(String[] args) {
        StringTest st = new StringTest();
        User u = new User("zhangsan", 4);
//        st.changeUser(u);
        // System.out.println(u.name);

//        st.changeUserName(u.name);
//        System.out.println(u.name);

//        st.newUser(u);
//        System.out.println(u);

        String a = "A";
        st.testCalledByReOrVal(a);
        System.out.println(a);

    }

    public void testNonInit() {
        System.out.println("s:"+s);
    }

    public void testNewString() {
        String a1 = "a";
        String a2 = new String("a");

        String ab1 = "ab";
        String ab2 = a1 + "b";
        String ab3 = a2 + "b";


        System.out.println(a1 == a2); // false
        System.out.println(a1.equals(a2)); // true

        System.out.println(ab1 == ab2); // false
        System.out.println(ab1 == ab3); // false
        System.out.println(ab2 == ab3); // false

        System.out.println(ab1.equals(ab2)); // true
        System.out.println(ab1.equals(ab3)); // true
        System.out.println(ab2.equals(ab3)); // true
    }

    static class User{
        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }
        public String name;
        public int age;

        @Override
        public String toString(){
            return "userName: " + name + "age: " + age;
        }
    }

    public void changeUser(User u) {
        u.name = "改变了";
    }

    public void changeUserName(String userName) {
        userName = "传入的姓名被改变了";
    }

    public void newUser(User u) {
        u = new User("new userName", 16);
    }

    public void testCalledByReOrVal(String str) {
        str += "is str";
    }
}
